layui.use(['table', 'admin', 'ax','laydate','form','element'], function () {
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;
    var $ax = layui.ax;
    var admin = layui.admin;
    var date = layui.laydate;
    var element = layui.element;


    var ajax = new $ax(Feng.ctxPath + "/ddbxd/detail/"+Feng.getUrlParam("id"), function (data) {
        var bxd=data.data;
        var base="";
        var stepCont="";
        base+="<tr><td>标题</td><td>"+bxd.title+"</td></tr>";
        base+="<tr><td>状态</td>"+getRs(bxd.status)+"</tr>";
        base+="<tr><td>结果</td>"+getRs(bxd.result)+"</tr>";
        base+="<tr><td>门店</td><td>"+bxd.originatorDeptName+"</td></tr>";
        base+="<tr><td>提交时间</td><td>"+bxd.createTime+"</td></tr>";
        $('#base').html(base);

        for(var t of bxd.tasks){
            stepCont+="<tr><td>"+t.userName+"</td>"+getRs(t.taskResult)+"<td>"+t.createTime+"</td></tr>";
        }
        $('#steps').append(stepCont);

        //拼接明细
        var costs=bxd.formComponentValues;
        var mx=costs[0];

        var attch=costs[2];
        var extValue = eval('(' + mx.extValue + ')');
        var dtl = eval('(' + mx.value + ')');
        var total = extValue.statValue[0];
        // s+="总报销金额："+total.num+"元<br/>";
        var ss="";
        var i=1;
        for(var t of dtl){
            ss+=getMx(t.rowValue);
            i++;
        }


        ss+="<tr><td>总金额</td><td colspan='3'></td><td>"+total.num+"</td></tr>";
        var pics=costs[1];

        if(pics.value!="null"){
            var ps=pics.value;
            var picjson = eval('('+ps+')');
            var srcary=ps.split(",");
            ss+="<tr><td>图片</td><td colspan='4'>";
            for(var src of picjson){
                ss+="<img src='"+src+"' />";
            }
            ss+="</td></tr>";

        }
        $('#mx').append(ss);
    }, function (data) {
        Feng.error("同步失败!" + data.responseJSON.message + "!");
    });
    ajax.start();


});

function getRs(st) {
    var rs="";
    var red=false;
    switch (st) {
        case "agree":rs="同意";break;
        case "refuse":rs="拒绝";red=true;break;
        case "AGREE":rs="同意";break;
        case "REFUSE":rs="拒绝";red=true;break;
        case "REDIRECTED":rs="转交";break;
        case "NONE":rs="无";break;
        case "NEW":rs="刚申报";break;
        case "RUNNING":rs="审批中";break;
        case "TERMINATED":rs="被终止";red=true;break;
        case "COMPLETED":rs="已完成";break;
        default : break;
    }
    return red?"<td class='red'>"+rs+"</td>":"<td>"+rs+"</td>";
}

function getMx(expend) {
    var bxr="";
    var dm="";
    var je="";
    var lb="";
    var mx="";
    for(var e of expend){
        switch (e.label) {
            case "报销人员": bxr= e.value;break;
            case "报销金额": je= e.value;break;
            case "报销类别": lb= e.value;break;
            case "费用明细": mx= e.value;break;
            case "申请店面": dm= e.value;break;
        }
    }
    return "<tr><td>"+dm+"</td><td>"+bxr+"</td>" +
        "<td>"+lb+"</td><td>"+mx+"</td>" +
        "<td>"+je+"</td></tr>";
}